package com.ganzalang.gmall.designpatterns.singleton.lazyload;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;

/**
 * @description: 双重检查锁定
 * @author: ganzalang
 */
@Slf4j
public class DoubleCheckLazyLoadSingleton {

    private static DoubleCheckLazyLoadSingleton singleton;

    private DoubleCheckLazyLoadSingleton() {

    }

    public static DoubleCheckLazyLoadSingleton getInstance() {
        if (singleton == null) { // 1
            synchronized (DoubleCheckLazyLoadSingleton.class) { // 2
                if (singleton == null) { // 3
                    singleton = new DoubleCheckLazyLoadSingleton(); // 4
                }
            }
        }
        return singleton; // 5
    }
}
